<?php
namespace app\manager\controller;
use Endroid\QrCode\QrCode;

class CarBrand extends BaseController
{
    protected $check_auths = false; 
    /**
     * GET shwo carbrand info list
     * @return [type] [description]
     */

    public function index()
    {
        $list = model('CarBrands')->getCarBrandsLists();
        $this->assign('list',$list);
        return view('p/carbrand/index');
    }
    /**
     * GET show carbrand info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function read($id)
    {
        
    }

    /**
     * GET shwo create carbrand info
     * @return [type] [description]
     */
    public function create()
    {
        
        return view('p/carbrand/create');
    }

    /**
     * POST create new carbrand info
     * @return [type] [description]
     */
    public function save()
    {
        
        $post_carbrand_info['name'] = input('post.name');
        $post_carbrand_info['profiles'] = input('post.profiles');

        $carbrand = model('CarBrands')->createCarBrand($post_carbrand_info);
        
        if($carbrand){
            return $this->success(lang('create carbrand success'), '/carbrand');
        }
            return $this->error(lang('create carbrand failed').$carbrand['msg']);        
    }
    /**
     * GET edit carbrand info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function edit($id)
    {
        $data = model('CarBrands')->getCarBrandInfo($id);
        $this->assign('data',$data);
        $this->assign('id',$id);
        return view('p/carbrand/edit');
    }

    /**
     * PUT update carbrand info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function update($id)
    {
        
        $post_carbrand_info['name'] = input('post.name');
        $post_carbrand_info['profiles'] = input('post.profiles');
        
        $carbrand = model('CarBrands')->updateCarBrand($id, $post_carbrand_info);

        if($carbrand){
            return $this->success(lang('update carbrand success'), '/carbrand');
        }
            return $this->error(lang('update carbrand failed').$carbrand['msg']);
    }

    /**
     * DELETE carbrand info
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function delete($id)
    {
       $ids=input('post.ids/a');
        if (empty($ids)) {
          return $this->error('请选择要删除的选项'); 
        }
        $count = model('CarBrands')->delInfo($ids);
        if ($count) {
           return $this->success('删除成功','/carbrand');
        }
        return $this->error('删除失败');
    }
}

